package com.hangzhou.xyj.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.hangzhou.xyj.R;
import com.hangzhou.xyj.manager.IntentManager;
import com.hangzhou.xyj.model.GroupModel;
import com.hangzhou.xyj.ui.adapter.base.BaseLoadingAdapter;
import com.hangzhou.xyj.ui.widget.CircleImageView;
import com.hangzhou.xyj.ui.widget.views.MyTextView;

import java.util.List;

/**
 * Created by Administrator on 2016/1/19.
 */
public class MoreGroupAdapter extends BaseLoadingAdapter<GroupModel> {

    public MoreGroupAdapter(RecyclerView recyclerView, List<GroupModel> list) {
        super(recyclerView, list);
    }

    @Override
    public void onBindNormalViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ((MyViewHolder) holder).setData(mDataList.get(position));
        if (position == 0) {
            ((MyViewHolder) holder).mVPaddingTop.setVisibility(View.VISIBLE);
        } else {
            ((MyViewHolder) holder).mVPaddingTop.setVisibility(View.GONE);
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IntentManager.getInstance().goGroupDetailActivity(mContext, mDataList.get(position).getGroupCode());
            }
        });
    }

    @Override
    public RecyclerView.ViewHolder onCreateNormalViewHolder(ViewGroup parent, int viewType) {
        View itemView = View.inflate(mContext, R.layout.layout_group_item, null);
        return new MyViewHolder(itemView);
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        CircleImageView mIvImage;//圈子图片
        MyTextView mTvGroupName;//圈子名称
        MyTextView mTvCls;//圈子类别
        MyTextView mTvId;//圈子ID
        View mVPaddingTop;//上面的padding

        public MyViewHolder(View itemView) {
            super(itemView);
            mIvImage = (CircleImageView) itemView.findViewById(R.id.tv_group_img);
            mTvGroupName = (MyTextView) itemView.findViewById(R.id.tv_group_name);
            mTvCls = (MyTextView) itemView.findViewById(R.id.tv_group_cls);
            mTvId = (MyTextView) itemView.findViewById(R.id.tv_group_id);
            mVPaddingTop = itemView.findViewById(R.id.v_padding_top);
        }

        public void setData(GroupModel data) {
            mIvImage.displayImage(data.getGroupImage());
            mTvGroupName.setText(data.getGroupName());
            mTvCls.setText(data.getGroupCls());
            mTvId.setText(data.getId());
        }
    }
}
